/**
 * 
 */
package com.nervytech.tutorcruise.db.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nervytech.tutorcruise.db.dao.interfaces.ICourseMasterDAO;
import com.nervytech.tutorcruise.db.dao.model.CourseMaster;
import com.nervytech.tutorcruise.db.service.interfaces.ICourseMasterService;
import com.nervytech.tutorcruise.service.exception.TrainerCruiseServiceException;

/**
 * @author ADMIN
 * 
 */
@Service("courseMasterService")
public class CourseMasterService implements ICourseMasterService {

	@Autowired
	private ICourseMasterDAO courseMasterDAO;

	@Override
	public void saveCourseOverview(CourseMaster courseMaster)
			throws TrainerCruiseServiceException {
		try {
			courseMasterDAO.saveCourseOverview(courseMaster);
		} catch (Exception e) {
			throw new TrainerCruiseServiceException(e.getMessage());
		}
	}

	@Override
	public void updateCourseOverview(CourseMaster courseMaster)
			throws TrainerCruiseServiceException {
		try {
			courseMasterDAO.updateCourseOverview(courseMaster);
		} catch (Exception e) {
			throw new TrainerCruiseServiceException(e.getMessage());
		}

	}

	@Override
	public void updateCourseAgenda(CourseMaster courseMaster)
			throws TrainerCruiseServiceException {
		try {
			courseMasterDAO.updateCourseAgenda(courseMaster);
		} catch (Exception e) {
			throw new TrainerCruiseServiceException(e.getMessage());
		}

	}

	@Override
	public CourseMaster getCourseOverview(long userId, long courseId)
			throws TrainerCruiseServiceException {
		CourseMaster courseMaster = null;
		List<CourseMaster> courseMasterList = null;
		try {
			courseMasterList = courseMasterDAO.getCourseOverview(userId,
					courseId);
			if (courseMasterList.size() > 0)
				courseMaster = courseMasterList.get(0);
		} catch (Exception e) {
			throw new TrainerCruiseServiceException(e.getMessage());
		}
		return courseMaster;
	}

	@Override
	public CourseMaster getCourseAgenda(long userId, long courseMasterId)
			throws TrainerCruiseServiceException {
		CourseMaster courseMaster = null;
		List<CourseMaster> courseMasterList = null;
		try {
			courseMasterList = courseMasterDAO.getCourseAgenda(userId,
					courseMasterId);
			if (courseMasterList.size() > 0)
				courseMaster = courseMasterList.get(0);
		} catch (Exception e) {
			throw new TrainerCruiseServiceException(e.getMessage());
		}
		return courseMaster;
	}

}
